package com.fare.taluo.application.plane.city;

import java.util.ArrayList;
import java.util.List;

import org.apache.struts2.json.annotations.JSON;

import com.fare.taluo.core.domain.config.city.CityEntity;
import com.fare.taluo.core.domain.config.city.PortEntity;
/**
 * 树
 * @author lyq
 *
 */
public class ComboTree {
	
	public final static Long ROOT_ID = 1L;
	
	public ComboTree(){}
	
	public ComboTree(PortEntity port){
		this.id = port.getId();
		this.text = port.getName();
		this.pid = port.getCityId();
		this.treeType = CityEntity.PORT;
		this.treeSort = port.getPriority();
	} 
	
	public ComboTree(CityEntity city){
		this.id = city.getId();
		this.text = city.getName();
		this.pid = city.getPid();
		this.treeType = city.getTreeType();
		this.treeSort = city.getTreeSort();
	}
	
	public ComboTree(List <ComboTree> children){
		this.children = children;
	}

	
	private Long id ;
	private Long pid;
	private String text;
	private Integer treeType;
	private Integer treeSort;
	private boolean isexpand = false;
	private boolean hasChild;
	private List<ComboTree> children = new ArrayList<ComboTree>();

	public void setIsexpand(boolean isexpand) {
		this.isexpand = isexpand;
	}

	public void setHasChild(boolean hasChild) {
		this.hasChild = hasChild;
	}

	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public Long getPid() {
		return pid;
	}

	public void setPid(Long pid) {
		this.pid = pid;
	}

	public Integer getTreeSort() {
		return treeSort;
	}

	public void setTreeSort(Integer treeSort) {
		this.treeSort = treeSort;
	}

	public String getText() {
		return text;
	}

	public void setText(String text) {
		this.text = text;
	}

	public Integer getTreeType() {
		return treeType;
	}

	public void setTreeType(Integer treeType) {
		this.treeType = treeType;
	}

	public List<ComboTree> getChildren() {
		return children;
	}

	public void setChildren(List<ComboTree> children) {
		this.children = children;
	}
	
	@JSON(name="isexpand")
	public boolean getIsExpand() {
		return ComboTree.ROOT_ID != this.getPid() || isexpand;
	}
	@JSON(name="hasChild")
	public boolean getHasChild(){
		return !children.isEmpty() || hasChild;
	}
}
